__author__  = "Avinash Vora"
__version__ = "v 1.0"

import string

def format_string(text, pad_char="Z", groups=4):
	"""Formats a string in preparation for ciphering."""
	
	# initialize parameters
	x, y = 0, groups
	formatted = []
	
	# remove punctuation and whitespace
	text = "".join([letter for letter in text if letter not in string.punctuation])
	text = "".join([letter for letter in text if letter not in string.whitespace])
	text = text.upper()
	
	# pad the string with pad_char="Z" to make it a multiple of groups=4
	if len(text) % groups:
		text += pad_char * (groups - (len(text) % groups))
	
	# split the string into groups=4
	while y <= len(text):
		formatted.append(text[x:y])
		x, y = x + groups, y + groups
	
	return formatted

def cipher(source, key):
	"""Ciphers a source string given a key"""
	
	# initialize parameters
	result = []
	
	# format the source and key
	source = format_string(source)
	key = format_string(key)
	
	return result
	
if __name__ == "__main__":
	test_text = "Hello, how are you?  I am doing fine, thank you."
	print format_string(test_text)